//引入mongodb相关路径
require('./util/dbConnect')
require('./models/exercisesModel')
require('./models/testsModel')
require('./models/pointsModel')
require('./models/collectionsModel')
require('./models/testedsModel')
require('./models/errorsModel')
require('./models/studentsModel')
require('./models/indexModel')
require('./models/typesModel')


var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');



//77
let collectionsRouter=require('./routes/collections.js');
let rankingRouter=require('./routes/ranking.js');
let exercisesRouter=require('./routes/exercises.js');
let pointsRouter=require('./routes/points.js')
//引入目标JS文件
//天
let students=require('./routes/studentsDemo.js');
let typesDemo=require('./routes/typesDemo.js');
let errorsDemo=require('./routes/errors');
let indexDemo=require('./routes/indexDemo');

//钟
let testeds=require('./routes/testeds.js');
let modified=require('./routes/modified.js');
let auth=require('./routes/auth.js')

let tests=require('./routes/tests-basic-info.js');
let answers=require('./routes/answers');

//引入鉴权  钟

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
let config=require('./util/authConfig.js');
const { use } = require('./routes/studentsDemo.js')
app.use(config)

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

//77
app.use('/collection',collectionsRouter);
app.use('/ranking',rankingRouter);
app.use('/exercise',exercisesRouter);
app.use('/point',pointsRouter);

//天
app.use('/students',students);
app.use('/typesDemo',typesDemo);
app.use('/errorsDemo',errorsDemo);
app.use('/indexDemo',indexDemo)

//钟
app.use('/testeds',testeds);
app.use('/modified',modified);
app.use('/auth',auth)

app.use('/tests',tests);
app.use('/answers',answers);



// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

// module.exports = app;
app.listen(3000,function(){
  console.log("服务器接口3000 启用成功");
})
